package com.dingdang.controller.car_detail_management;


import com.dingdang.data.Result;
import com.dingdang.em.ResultEnum;
import com.dingdang.entity.CarVehicle;
import com.dingdang.mapper.CarVehicleMapper;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

@RestController
@RequestMapping("CarVehicle")
@Api("车辆评估接口")
public class CarVehicleController
{
    @Autowired
    private CarVehicleMapper carVehicleMapper;

    //搜索
    @GetMapping
    @ApiOperation("车辆评估搜索")
    @ApiImplicitParam(name = "void",value = "空",required = true,paramType = "query")
    public Result selectUser()
    {
        List<CarVehicle> carVehicleList = carVehicleMapper.selectList(null);
        return Result.response(ResultEnum.SUCCESS).setData(carVehicleList);
    }

    //用户增加
    @PostMapping
    @ApiOperation("用户增加")
    @ApiImplicitParam(name = "CarVehicle",value = "车辆评估实体类",required = true,paramType = "body")
    public Result insertUser(@RequestBody CarVehicle carVehicle)
    {
        int i = carVehicleMapper.insert(carVehicle);
        if (i==1)
        {
            return Result.response(ResultEnum.SUCCESS);
        }
        else
        {
            return Result.response(ResultEnum.ERROR);
        }
    }

    //用户回显
    @PostMapping("/userToUpdate")
    @ApiOperation("车辆评估回显")
    @ApiImplicitParam(name = "id",value = "车辆评估id",required = true,paramType = "query")
    public Result ToUpdateUser(@RequestParam("id") Long id)
    {
        CarVehicle carVehicle = carVehicleMapper.selectById(id);
        return Result.response(ResultEnum.SUCCESS).setData(carVehicle);
    }

    //用户修改
    @PutMapping
    @ApiOperation("车辆评估修改")
    @ApiImplicitParam(name = "CarVehicle",value = "车辆评估实体类",required = true,paramType = "body")
    public Result UpdateUser(@RequestBody CarVehicle carVehicle)
    {
        int i = carVehicleMapper.updateById(carVehicle);
        if (i==1)
        {
            return Result.response(ResultEnum.SUCCESS);
        }
        else
        {
            return Result.response(ResultEnum.ERROR);
        }
    }

    @DeleteMapping()
    @ApiOperation("车辆评估删除")
    @ApiImplicitParam(name = "id",value = "车辆评估id",required = true,paramType = "query")
    public Result deleteInfo(@RequestParam(value = "id") Long []ids)
    {
        List<Long> deleteBatch = new ArrayList<>();
        for (Long addr:ids)
        {
            deleteBatch.add(addr);
        }
        int i = carVehicleMapper.deleteBatchIds(deleteBatch);
        if (i==1)
        {
            return Result.response(ResultEnum.SUCCESS);
        }
        else
        {
            return Result.response(ResultEnum.ERROR);
        }
    }
}
